package com.jianyun.jyzs.model;

import com.jianyun.jyzs.bean.AnnouncementComment;
import com.jianyun.jyzs.bean.AnnouncementList;
import com.jianyun.jyzs.bean.DiscussResult;
import com.jianyun.jyzs.bean.NoticeAgreesCountResult;
import com.jianyun.jyzs.bean.SinglAnnoucement;
import com.jianyun.jyzs.dao.AnnCommentDao;
import com.jianyun.jyzs.dao.AnnouncementDao;
import com.jianyun.jyzs.http.Api;
import com.jianyun.jyzs.http.CustomCallback;
import com.jianyun.jyzs.http.RetrofitHelper;
import com.jianyun.jyzs.model.imdoel.IAnnounceDetailModel;

import java.util.HashMap;
import java.util.List;

import com.jianyun.jyzs.utils.RceLog;

import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by yangshijun on 2018/5/29.
 */

public class AnnounceDetailModel implements IAnnounceDetailModel {

    private static AnnounceDetailModel model;

    private AnnounceDetailModel() {
    }

    public static AnnounceDetailModel getInstance() {
        if (model == null) {
            model = new AnnounceDetailModel();
        }
        return model;
    }

    /**
     * 获取单个公告详情
     *
     * @param dao
     * @param newsId
     * @param listener
     */
    @Override
    public void getAccounceDetailById(final AnnouncementDao dao, String newsId, OnAnnounceDetailListener listener) {
        /*try {
            Api api = RetrofitHelper.builderbch().create(Api.class);
            api.getSinglAnnou(newsId).observeOn(AndroidSchedulers.mainThread())
                    .subscribeOn(Schedulers.io())
                    .subscribe(new CustomCallback<SinglAnnoucement>() {
                        @Override
                        protected void onResponse(SinglAnnoucement response) {
                            RceLog.d("lml", "单个公告详情" + response.toString());
                            AnnouncementList.Announcement po = response.getPo();
                            po.setIsread(false);
                            dao.coninsert(po);
                        }

                        @Override
                        protected void onException(String msg) {

                        }
                    });
        } catch (Exception e) {
            e.printStackTrace();
        }*/

    }

    /**
     * 点赞
     *
     * @param map
     * @param listener
     */
    @Override
    public void commmitLike(HashMap<String, String> map, final OnLikeAnnounceListener listener) {
        /*try {
            Api api = RetrofitHelper.builderbch().create(Api.class);
            api.likesAnnouncement(map).observeOn(AndroidSchedulers.mainThread())
                    .subscribeOn(Schedulers.io())
                    .subscribe(new CustomCallback<NoticeAgreesCountResult>() {
                        @Override
                        protected void onResponse(NoticeAgreesCountResult response) {
                            if (response.isResult()) {
                                listener.onSuccess();
                            } else {
                                listener.onFailed(response.getMessage());
                            }
                        }

                        @Override
                        protected void onException(String msg) {
                            listener.onFailed(msg);
                        }
                    });
        } catch (Exception e) {
            e.printStackTrace();
        }*/

    }

    /**
     * 提交评论
     *
     * @param map
     * @param listener
     */
    @Override
    public void commitComment(HashMap<String, String> map, final OnCommentAnnounceListener listener) {
        /*try {
            Api api = RetrofitHelper.builderbch().create(Api.class);
            api.commentAnnoucement(map).observeOn(AndroidSchedulers.mainThread())
                    .subscribeOn(Schedulers.io())
                    .subscribe(new CustomCallback<DiscussResult>() {
                        @Override
                        protected void onResponse(DiscussResult response) {

                            if (response.isResult()) {
                                listener.onSuccess();
                            } else {
                                listener.onFailed(response.getMessage());
                            }
                        }

                        @Override
                        protected void onException(String msg) {
                            listener.onFailed(msg);
                        }
                    });
        } catch (Exception e) {
            e.printStackTrace();
        }*/

    }

    /**
     * 获取公告评论
     *
     * @param dao
     * @param map
     * @param enterpriseCode
     * @param listener
     */
    @Override
    public void getAccounceComment(final AnnCommentDao dao, HashMap<String, String> map, final String enterpriseCode, final OnGetCommnetAnnounceListener listener) {
        /*try {
            Api api = RetrofitHelper.builderbch().create(Api.class);
            api.getAnnCommentList(map).observeOn(AndroidSchedulers.mainThread())
                    .subscribeOn(Schedulers.io())
                    .subscribe(new CustomCallback<AnnouncementComment>() {
                        @Override
                        protected void onResponse(AnnouncementComment response) {
                            RceLog.d("lml", response.toString());
                            if (response.isResult()) {
                                List<AnnouncementComment.AnnComment> list = response.getList();
                                for (AnnouncementComment.AnnComment ann : list) {
                                    dao.insert(ann, enterpriseCode);
                                }
                                listener.onSuccess();
                            } else {
                                listener.onFailed(response.getMessage());
                            }

                        }

                        @Override
                        protected void onException(String msg) {
                            listener.onFailed(msg);
                        }
                    });
        } catch (Exception e) {
            e.printStackTrace();
        }*/

    }
}
